﻿using System;
using Ewk.Math.Algebra.Algorithms.Matrices;
using Ewk.Math.Algebra.Algorithms.Matrices.Determinant;
using Ewk.Math.ComputationTypes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests.Determinant.DeterminantManipulationsTests.Int32Tests
{
    [TestClass]
    public class DivideComputableInt32Tests : DeterminantManipulationsInt32Base
    {
        [TestMethod]
        public void When_Divide_Is_Called_With_A_Computable_Then_The_Value_Of_The_Determinant_Must_Sized()
        {
            const int factorValue = 3;
            var factor = CreateComputable(factorValue);

            IMatrixManipulations<int, Computable<int>> manipulations = new DeterminantManipulator<int>(Matrix, Determinant);
            var result = manipulations.Divide(factor);

            Assert.AreEqual(factor.Value, 3); // Factor remains untouched
            Assert.AreEqual(System.Math.Pow(1/factorValue, 3), result.Value);
        }

        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void When_Divide_Is_Called_With_Null_Then_An_ArgumentNullException_Is_Thrown()
        {
            IMatrixManipulations<int, Computable<int>> manipulations = new DeterminantManipulator<int>(Matrix, Determinant);
            manipulations.Divide(null);
        }

        [TestMethod]
        public void When_Divide_Is_Called_With_A_Computable_And_A_Null_Determinant_Then_The_Result_Is_Null()
        {
            const int factorValue = 3;
            var factor = CreateComputable(factorValue);

            IMatrixManipulations<int, Computable<int>> manipulations = new DeterminantManipulator<int>(Matrix, null);
            var result = manipulations.Divide(factor);

            Assert.AreEqual(factor.Value, 3); // Factor remains untouched
            Assert.IsNull(result);
        }
    }
}